package ynu.edu.order.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import ynu.edu.order.constans.MQConstants;

/**
 * 订单延迟队列配置
 * 只配置延迟队列，不包含死信队列
 */
@Configuration
public class OrderDelayConfig {

    /**
     * 延迟交换机
     */
    @Bean
    public DirectExchange delayExchange() {
        return new DirectExchange(MQConstants.DELAY_EXCHANGE_NAME, true, false);
    }

    /**
     * 延迟队列
     * 注意：这里不需要死信队列配置，因为延迟消息本身就是基于TTL机制
     */
    @Bean
    public Queue delayOrderQueue() {
        return QueueBuilder.durable(MQConstants.DELAY_ORDER_QUEUE_NAME)
                .build();
    }

    /**
     * 绑定延迟队列和交换机
     */
    @Bean
    public Binding delayOrderBinding() {
        return BindingBuilder.bind(delayOrderQueue())
                .to(delayExchange())
                .with(MQConstants.DELAY_ORDER_KEY);
    }
} 